<!doctype html>
<html>
  <head>
    <title>XHR test</title>
  </head>
  <body>
    <a id="start">start</a>

    <script>
      // new 3.503000014461577
      // event 3.3499999553896487
      // open 7.528000045567751
      // send 3.596999973524362

      // new 11.197000043466687
      // event 6.705000007059425
      // open 189.40799997653812
      // send 27.663999993819743

      var startLink = document.getElementById('start');
      startLink.onclick = function() {
        var start = performance.now();

        var count = 2000;
        var xhrs = new Array(count);
        var t0 = performance.now();
        for (var n = 0; n < count; n++) {
          xhrs[n] = new XMLHttpRequest();
        }
        var t1 = performance.now();
        for (var n = 0; n < count; n++) {
          xhrs[n].onload = function() {
          };
        }
        var t2 = performance.now();
        for (var n = 0; n < count; n++) {
          xhrs[n].open('GET', 'http://mt0.google.com/vt/vec?src=vector&x=332&y=716&z=11&hl=en&lyrs=m@207690615&output=webgl8&other=' + (count + Date.now()), true);
        }
        var t3 = performance.now();
        for (var n = 0; n < count; n++) {
          xhrs[n].send();
        }
        var t4 = performance.now();

        var duration = performance.now() - start;
        console.log(duration / count);
        console.log('new', t1 - t0, 'event', t2 - t1, 'open', t3 - t2, 'send', t4 - t3);
      };
    </script>
  </body>
</html>
